<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>Reindex API | Elasticsearch Guide [7.7] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch Guide [7.7]">
<link rel="up" href="docs.html" title="Document APIs">
<link rel="prev" href="docs-bulk.html" title="Bulk API">
<link rel="next" href="docs-termvectors.html" title="Term vectors API">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/7.7">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="7.7">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<strong>IMPORTANT</strong>: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
<a href="../current/index.html">current release documentation</a>.
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="docs.html">Document APIs</a></span>
»
<span class="breadcrumb-node">Reindex API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="docs-bulk.html">« Bulk API</a>
</span>
<span class="next">
<a href="docs-termvectors.html">Term vectors API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="docs-reindex"></a>Reindex API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Copies documents from one index to another.</p>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>Reindex requires <a class="xref" href="mapping-source-field.html" title="_source field"><code class="literal">_source</code></a> to be enabled for
all documents in the source index.</p>
<p>You must set up the destination index before calling <code class="literal">_reindex</code>.
Reindex does not copy the settings from the source index.
Mappings, shard counts, replicas, and so on must be configured ahead of time.</p>
</div>
</div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1535.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-reindex-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">POST /_reindex</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-reindex-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Extracts the document source from the source index and indexes the documents into the destination index.
You can copy all documents to the destination index, or reindex a subset of the documents.</p>
<p>Just like <a class="xref" href="docs-update-by-query.html" title="Update by query API"><code class="literal">_update_by_query</code></a>, <code class="literal">_reindex</code> gets a
snapshot of the source index but its target must be a <span class="strong strong"><strong>different</strong></span> index so
version conflicts are unlikely. The <code class="literal">dest</code> element can be configured like the
index API to control optimistic concurrency control. Omitting
<code class="literal">version_type</code> or setting it to <code class="literal">internal</code> causes Elasticsearch
to blindly dump documents into the target, overwriting any that happen to have
the same ID.</p>
<p>Setting <code class="literal">version_type</code> to <code class="literal">external</code> causes Elasticsearch to preserve the
<code class="literal">version</code> from the source, create any documents that are missing, and update
any documents that have an older version in the destination index than they do
in the source index.</p>
<p>Setting <code class="literal">op_type</code> to <code class="literal">create</code> causes <code class="literal">_reindex</code> to only create missing
documents in the target index. All existing documents will cause a version
conflict.</p>
<p>By default, version conflicts abort the <code class="literal">_reindex</code> process.
To continue reindexing if there are conflicts, set the <code class="literal">"conflicts"</code> request body parameter to <code class="literal">proceed</code>.
In this case, the response includes a count of the version conflicts that were encountered.
Note that the handling of other error types is unaffected by the <code class="literal">"conflicts"</code> parameter.</p>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-task-api"></a>Running reindex asynchronously<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>If the request contains <code class="literal">wait_for_completion=false</code>, Elasticsearch
performs some preflight checks, launches the request, and returns a
<a class="xref" href="tasks.html" title="Task management API"><code class="literal">task</code></a> you can use to cancel or get the status of the task.
Elasticsearch creates a record of this task as a document at <code class="literal">.tasks/task/${taskId}</code>.
When you are done with a task, you should delete the task document so
Elasticsearch can reclaim the space.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-many-indices"></a>Reindexing many indices<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>If you have many indices to reindex it is generally better to reindex them
one at a time rather than using a glob pattern to pick up many indices. That
way you can resume the process if there are any errors by removing the
partially completed index and starting over at that index. It also makes
parallelizing the process fairly simple: split the list of indices to reindex
and run each list in parallel.</p>
<p>One-off bash scripts seem to work nicely for this:</p>
<div class="pre_wrapper lang-bash">
<pre class="programlisting prettyprint lang-bash">for index in i1 i2 i3 i4 i5; do
  curl -HContent-Type:application/json -XPOST localhost:9200/_reindex?pretty -d'{
    "source": {
      "index": "'$index'"
    },
    "dest": {
      "index": "'$index'-reindexed"
    }
  }'
done</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-throttle"></a>Throttling<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Set <code class="literal">requests_per_second</code> to any positive decimal number (<code class="literal">1.4</code>, <code class="literal">6</code>,
<code class="literal">1000</code>, etc.) to throttle the rate at which <code class="literal">_reindex</code> issues batches of index
operations. Requests are throttled by padding each batch with a wait time.
To disable throttling, set <code class="literal">requests_per_second</code> to <code class="literal">-1</code>.</p>
<p>The throttling is done by waiting between batches so that the <code class="literal">scroll</code> that <code class="literal">_reindex</code>
uses internally can be given a timeout that takes into account the padding.
The padding time is the difference between the batch size divided by the
<code class="literal">requests_per_second</code> and the time spent writing. By default the batch size is
<code class="literal">1000</code>, so if <code class="literal">requests_per_second</code> is set to <code class="literal">500</code>:</p>
<div class="pre_wrapper lang-txt">
<pre class="programlisting prettyprint lang-txt">target_time = 1000 / 500 per second = 2 seconds
wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds</pre>
</div>
<p>Since the batch is issued as a single <code class="literal">_bulk</code> request, large batch sizes
cause Elasticsearch to create many requests and then wait for a while before
starting the next set. This is "bursty" instead of "smooth".</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-rethrottle"></a>Rethrottling<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The value of <code class="literal">requests_per_second</code> can be changed on a running reindex using
the <code class="literal">_rethrottle</code> API:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex/r1A2WoRbTwKZ516z6NEs5A:36619/_rethrottle?requests_per_second=-1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1536.console"></div>
<p>The task ID can be found using the <a class="xref" href="tasks.html" title="Task management API">tasks API</a>.</p>
<p>Just like when setting it on the Reindex API, <code class="literal">requests_per_second</code>
can be either <code class="literal">-1</code> to disable throttling or any decimal number
like <code class="literal">1.7</code> or <code class="literal">12</code> to throttle to that level. Rethrottling that speeds up the
query takes effect immediately, but rethrottling that slows down the query will
take effect after completing the current batch. This prevents scroll
timeouts.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-slice"></a>Slicing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Reindex supports <a class="xref" href="search-request-body.html#sliced-scroll" title="Sliced Scroll">Sliced Scroll</a> to parallelize the reindexing process.
This parallelization can improve efficiency and provide a convenient way to
break the request down into smaller parts.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Reindexing from remote clusters does not support
<a class="xref" href="docs-reindex.html#docs-reindex-manual-slice" title="Manual slicing">manual</a> or
<a class="xref" href="docs-reindex.html#docs-reindex-automatic-slice" title="Automatic slicing">automatic slicing</a>.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h5 class="title">
<a id="docs-reindex-manual-slice"></a>Manual slicing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h5>
</div></div></div>
<p>Slice a reindex request manually by providing a slice id and total number of
slices to each request:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "twitter",
    "slice": {
      "id": 0,
      "max": 2
    }
  },
  "dest": {
    "index": "new_twitter"
  }
}
POST _reindex
{
  "source": {
    "index": "twitter",
    "slice": {
      "id": 1,
      "max": 2
    }
  },
  "dest": {
    "index": "new_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1537.console"></div>
<p>You can verify this works by:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET _refresh
POST new_twitter/_search?size=0&amp;filter_path=hits.total</pre>
</div>
<div class="console_widget" data-snippet="snippets/1538.console"></div>
<p>which results in a sensible <code class="literal">total</code> like this one:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "hits": {
    "total" : {
        "value": 120,
        "relation": "eq"
    }
  }
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h5 class="title">
<a id="docs-reindex-automatic-slice"></a>Automatic slicing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h5>
</div></div></div>
<p>You can also let <code class="literal">_reindex</code> automatically parallelize using <a class="xref" href="search-request-body.html#sliced-scroll" title="Sliced Scroll">Sliced Scroll</a> to
slice on <code class="literal">_id</code>. Use <code class="literal">slices</code> to specify the number of slices to use:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex?slices=5&amp;refresh
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1539.console"></div>
<p>You can also this verify works by:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST new_twitter/_search?size=0&amp;filter_path=hits.total</pre>
</div>
<div class="console_widget" data-snippet="snippets/1540.console"></div>
<p>which results in a sensible <code class="literal">total</code> like this one:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "hits": {
    "total" : {
        "value": 120,
        "relation": "eq"
    }
  }
}</pre>
</div>
<p>Setting <code class="literal">slices</code> to <code class="literal">auto</code> will let Elasticsearch choose the number of slices
to use. This setting will use one slice per shard, up to a certain limit. If
there are multiple source indices, it will choose the number of slices based
on the index with the smallest number of shards.</p>
<p>Adding <code class="literal">slices</code> to <code class="literal">_reindex</code> just automates the manual process used in the
section above, creating sub-requests which means it has some quirks:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
You can see these requests in the <a class="xref" href="docs-reindex.html#docs-reindex-task-api" title="Running reindex asynchronously">Tasks APIs</a>. These
sub-requests are "child" tasks of the task for the request with <code class="literal">slices</code>.
</li>
<li class="listitem">
Fetching the status of the task for the request with <code class="literal">slices</code> only contains
the status of completed slices.
</li>
<li class="listitem">
These sub-requests are individually addressable for things like cancelation
and rethrottling.
</li>
<li class="listitem">
Rethrottling the request with <code class="literal">slices</code> will rethrottle the unfinished
sub-request proportionally.
</li>
<li class="listitem">
Canceling the request with <code class="literal">slices</code> will cancel each sub-request.
</li>
<li class="listitem">
Due to the nature of <code class="literal">slices</code> each sub-request won’t get a perfectly even
portion of the documents. All documents will be addressed, but some slices may
be larger than others. Expect larger slices to have a more even distribution.
</li>
<li class="listitem">
Parameters like <code class="literal">requests_per_second</code> and <code class="literal">max_docs</code> on a request with
<code class="literal">slices</code> are distributed proportionally to each sub-request. Combine that with
the point above about distribution being uneven and you should conclude that
using <code class="literal">max_docs</code> with <code class="literal">slices</code> might not result in exactly <code class="literal">max_docs</code> documents
being reindexed.
</li>
<li class="listitem">
Each sub-request gets a slightly different snapshot of the source index,
though these are all taken at approximately the same time.
</li>
</ul>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h5 class="title">
<a id="docs-reindex-picking-slices"></a>Picking the number of slices<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h5>
</div></div></div>
<p>If slicing automatically, setting <code class="literal">slices</code> to <code class="literal">auto</code> will choose a reasonable
number for most indices. If slicing manually or otherwise tuning
automatic slicing, use these guidelines.</p>
<p>Query performance is most efficient when the number of <code class="literal">slices</code> is equal to the
number of shards in the index. If that number is large (e.g. 500),
choose a lower number as too many <code class="literal">slices</code> will hurt performance. Setting
<code class="literal">slices</code> higher than the number of shards generally does not improve efficiency
and adds overhead.</p>
<p>Indexing performance scales linearly across available resources with the
number of slices.</p>
<p>Whether query or indexing performance dominates the runtime depends on the
documents being reindexed and cluster resources.</p>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-routing"></a>Reindex routing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>By default if <code class="literal">_reindex</code> sees a document with routing then the routing is
preserved unless it’s changed by the script. You can set <code class="literal">routing</code> on the
<code class="literal">dest</code> request to change this:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">keep</code>
</span>
</dt>
<dd>
Sets the routing on the bulk request sent for each match to the routing on
the match. This is the default value.
</dd>
<dt>
<span class="term">
<code class="literal">discard</code>
</span>
</dt>
<dd>
Sets the routing on the bulk request sent for each match to <code class="literal">null</code>.
</dd>
<dt>
<span class="term">
<code class="literal">=&lt;some text&gt;</code>
</span>
</dt>
<dd>
Sets the routing on the bulk request sent for each match to all text after
the <code class="literal">=</code>.
</dd>
</dl>
</div>
<p>For example, you can use the following request to copy all documents from
the <code class="literal">source</code> index with the company name <code class="literal">cat</code> into the <code class="literal">dest</code> index with
routing set to <code class="literal">cat</code>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "source",
    "query": {
      "match": {
        "company": "cat"
      }
    }
  },
  "dest": {
    "index": "dest",
    "routing": "=cat"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1541.console"></div>
<p>By default <code class="literal">_reindex</code> uses scroll batches of 1000. You can change the
batch size with the <code class="literal">size</code> field in the <code class="literal">source</code> element:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "source",
    "size": 100
  },
  "dest": {
    "index": "dest",
    "routing": "=cat"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1542.console"></div>
<p>Reindex can also use the <a class="xref" href="ingest.html" title="Ingest node">Ingest node</a> feature by specifying a
<code class="literal">pipeline</code> like this:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "source"
  },
  "dest": {
    "index": "dest",
    "pipeline": "some_ingest_pipeline"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1543.console"></div>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-reindex-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">refresh</code>
</span>
</dt>
<dd>
(Optional, Boolean) If <code class="literal">true</code>, the request refreshes affected shards to make
this operation visible to search. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_active_shards</code>
</span>
</dt>
<dd>
<p>(Optional, string) The number of shard copies that must be active before
proceeding with the operation. Set to <code class="literal">all</code> or any positive integer up
to the total number of shards in the index (<code class="literal">number_of_replicas+1</code>).
Default: 1, the primary shard.</p>
<p>See <a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">Active shards</a>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_completion</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, the request blocks until the operation is complete.
Defaults to <code class="literal">true</code>.
</dd>
<dt>
<span class="term">
<code class="literal">requests_per_second</code>
</span>
</dt>
<dd>
(Optional, integer) The throttle for this request in sub-requests per second.
Defaults to <code class="literal">-1</code> (no throttle).
</dd>
<dt>
<span class="term">
<code class="literal">scroll</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies how long a consistent view of
the index should be maintained for scrolled search.
</dd>
<dt>
<span class="term">
<code class="literal">slices</code>
</span>
</dt>
<dd>
(Optional, integer) The number of slices this task should be divided into.
Defaults to 1 meaning the task isn’t sliced into subtasks.
</dd>
<dt>
<span class="term">
<code class="literal">max_docs</code>
</span>
</dt>
<dd>
(Optional, integer) Maximum number of documents to process. Defaults to all
documents.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-reindex-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">conflicts</code>
</span>
</dt>
<dd>
(Optional, enum) Set to <code class="literal">proceed</code> to continue reindexing even if there are conflicts.
Defaults to <code class="literal">abort</code>.
</dd>
<dt>
<span class="term">
<code class="literal">source</code>
</span>
</dt>
<dd>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">index</code>
</span>
</dt>
<dd>
(Required, string) The name of the index you are copying <em>from</em>.
Also accepts a comma-separated list of indices to reindex from multiple sources.
</dd>
<dt>
<span class="term">
<code class="literal">max_docs</code>
</span>
</dt>
<dd>
(Optional, integer) The maximum number of documents to reindex.
</dd>
<dt>
<span class="term">
<code class="literal">query</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="query-dsl.html" title="Query DSL">query object</a>) Specifies the documents to reindex using the Query DSL.
</dd>
<dt>
<span class="term">
<code class="literal">remote</code>
</span>
</dt>
<dd>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">host</code>
</span>
</dt>
<dd>
(Optional, string) The URL for the remote instance of Elasticsearch that you want to index <em>from</em>.
Required when indexing from remote.
</dd>
<dt>
<span class="term">
<code class="literal">username</code>
</span>
</dt>
<dd>
(Optional, string) The username to use for authentication with the remote host.
</dd>
<dt>
<span class="term">
<code class="literal">password</code>
</span>
</dt>
<dd>
(Optional, string) The password to use for authentication with the remote host.
</dd>
<dt>
<span class="term">
<code class="literal">socket_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) The remote socket read timeout. Defaults to 30 seconds.
</dd>
<dt>
<span class="term">
<code class="literal">connect_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) The remote connection timeout. Defaults to 30 seconds.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">size</code>
</span>
</dt>
<dd>
{Optional, integer) The number of documents to index per batch.
Use when indexing from remote to ensure that the batches fit within the on-heap buffer,
which defaults to a maximum size of 100 MB.
</dd>
<dt>
<span class="term">
<code class="literal">slice</code>
</span>
</dt>
<dd>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">id</code>
</span>
</dt>
<dd>
(Optional, integer) Slice ID for <a class="xref" href="docs-reindex.html#docs-reindex-manual-slice" title="Manual slicing">manual slicing</a>.
</dd>
<dt>
<span class="term">
<code class="literal">max</code>
</span>
</dt>
<dd>
(Optional, integer) Total number of slices.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">sort</code>
</span>
</dt>
<dd>
<p>(Optional, list) A comma-separated list of <code class="literal">&lt;field&gt;:&lt;direction&gt;</code> pairs to sort by before indexing.
Use in conjunction with <code class="literal">max_docs</code> to control what documents are reindexed.</p>
<div class="warning admon">
<div class="icon"></div>
<div class="admon_content">
<h3>Deprecated in 7.6.</h3>
<p>Sort in reindex is deprecated. Sorting in reindex was never guaranteed to index documents in order and prevents further development of reindex such as resilience and performance improvements. If used in combination with <code class="literal">max_docs</code>, consider using a query filter instead.</p>
</div>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">_source</code>
</span>
</dt>
<dd>
(Optional, string) If <code class="literal">true</code> reindexes all source fields.
Set to a list to reindex select fields.
Defaults to <code class="literal">true</code>.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">dest</code>
</span>
</dt>
<dd>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">index</code>
</span>
</dt>
<dd>
(Required, string) The name of the index you are copying <em>to</em>.
</dd>
<dt>
<span class="term">
<code class="literal">version_type</code>
</span>
</dt>
<dd>
(Optional, enum) The versioning to use for the indexing operation.
Valid values: <code class="literal">internal</code>, <code class="literal">external</code>, <code class="literal">external_gt</code>, <code class="literal">external_gte</code>.
See <a class="xref" href="docs-index_.html#index-version-types" title="Version types">Version types</a> for more information.
</dd>
<dt>
<span class="term">
<code class="literal">op_type</code>
</span>
</dt>
<dd>
(Optional, enum) Set to create to only index documents that do not already exist (put if absent).
Valid values: <code class="literal">index</code>, <code class="literal">create</code>. Defaults to <code class="literal">index</code>.
</dd>
<dt>
<span class="term">
<code class="literal">type</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
<span class="Admonishment Admonishment--change">
[<span class="Admonishment-version u-mono u-strikethrough">6.0.0</span>]
<span class="Admonishment-detail">
Deprecated in 6.0.0. Types are deprecated and in the process of being removed. See <a class="xref" href="removal-of-types.html" title="Removal of mapping types"><em>Removal of mapping types</em></a>.
</span>
</span>
<a class="xref" href="mapping-type-field.html" title="_type field">Document type</a> for reindexed documents.
Defaults to <code class="literal">_doc</code>.
</p>
<div class="warning admon">
<div class="icon"></div>
<div class="admon_content">
<p>Types in source indices are always ignored, also when not specifying a
destination <code class="literal">type</code>. If explicitly specifying destination <code class="literal">type</code>, the specified
type must match the type in the destination index or be either unspecified or
the special value <code class="literal">_doc</code>. See <a class="xref" href="removal-of-types.html" title="Removal of mapping types"><em>Removal of mapping types</em></a> for further details.</p>
</div>
</div>
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">script</code>
</span>
</dt>
<dd>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">source</code>
</span>
</dt>
<dd>
(Optional, string) The script to run to update the document source or metadata when reindexing.
</dd>
<dt>
<span class="term">
<code class="literal">lang</code>
</span>
</dt>
<dd>
(Optional, enum) The script language: <code class="literal">painless</code>, <code class="literal">expression</code>, <code class="literal">mustache</code>, <code class="literal">java</code>.
For more information, see <a class="xref" href="modules-scripting.html" title="Scripting">Scripting</a>.
</dd>
</dl>
</div>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-reindex-api-response-body"></a>Response body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">took</code>
</span>
</dt>
<dd>
(integer) The total milliseconds the entire operation took.
</dd>
<dt>
<span class="term">
<code class="literal">timed_out</code>
</span>
</dt>
<dd>
{boolean) This flag is set to <code class="literal">true</code> if any of the requests executed during the
reindex timed out.
</dd>
<dt>
<span class="term">
<code class="literal">total</code>
</span>
</dt>
<dd>
(integer) The number of documents that were successfully processed.
</dd>
<dt>
<span class="term">
<code class="literal">updated</code>
</span>
</dt>
<dd>
(integer) The number of documents that were successfully updated,
i.e. a document with same ID already existed prior to reindex updating it.
</dd>
<dt>
<span class="term">
<code class="literal">created</code>
</span>
</dt>
<dd>
(integer) The number of documents that were successfully created.
</dd>
<dt>
<span class="term">
<code class="literal">deleted</code>
</span>
</dt>
<dd>
(integer) The number of documents that were successfully deleted.
</dd>
<dt>
<span class="term">
<code class="literal">batches</code>
</span>
</dt>
<dd>
(integer) The number of scroll responses pulled back by the reindex.
</dd>
<dt>
<span class="term">
<code class="literal">noops</code>
</span>
</dt>
<dd>
(integer) The number of documents that were ignored because the script used for
the reindex returned a <code class="literal">noop</code> value for <code class="literal">ctx.op</code>.
</dd>
<dt>
<span class="term">
<code class="literal">version_conflicts</code>
</span>
</dt>
<dd>
(integer) The number of version conflicts that reindex hits.
</dd>
<dt>
<span class="term">
<code class="literal">retries</code>
</span>
</dt>
<dd>
(integer) The number of retries attempted by reindex. <code class="literal">bulk</code> is the number of bulk
actions retried and <code class="literal">search</code> is the number of search actions retried.
</dd>
<dt>
<span class="term">
<code class="literal">throttled_millis</code>
</span>
</dt>
<dd>
(integer) Number of milliseconds the request slept to conform to <code class="literal">requests_per_second</code>.
</dd>
<dt>
<span class="term">
<code class="literal">requests_per_second</code>
</span>
</dt>
<dd>
(integer) The number of requests per second effectively executed during the reindex.
</dd>
<dt>
<span class="term">
<code class="literal">throttled_until_millis</code>
</span>
</dt>
<dd>
(integer) This field should always be equal to zero in a <code class="literal">_reindex</code> response. It only
has meaning when using the <a class="xref" href="docs-reindex.html#docs-reindex-task-api" title="Running reindex asynchronously">Task API</a>, where it
indicates the next time (in milliseconds since epoch) a throttled request will be
executed again in order to conform to <code class="literal">requests_per_second</code>.
</dd>
<dt>
<span class="term">
<code class="literal">failures</code>
</span>
</dt>
<dd>
(array) Array of failures if there were any unrecoverable errors during the process. If
this is non-empty then the request aborted because of those failures. Reindex
is implemented using batches and any failure causes the entire process to abort
but all failures in the current batch are collected into the array. You can use
the <code class="literal">conflicts</code> option to prevent reindex from aborting on version conflicts.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-reindex-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-select-query"></a>Reindex select documents with a query<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can limit the documents by adding a query to the <code class="literal">source</code>.
For example, the following request only copies tweets made by <code class="literal">kimchy</code> into <code class="literal">new_twitter</code>:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "twitter",
    "query": {
      "term": {
        "user": "kimchy"
      }
    }
  },
  "dest": {
    "index": "new_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1544.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-select-max-docs"></a>Reindex select documents with <code class="literal">max_docs</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can limit the number of processed documents by setting <code class="literal">max_docs</code>.
For example, this request copies a single document from <code class="literal">twitter</code> to
<code class="literal">new_twitter</code>:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "max_docs": 1,
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1545.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-multiple-indices"></a>Reindex from multiple indices<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The <code class="literal">index</code> attribute in <code class="literal">source</code> can be a list, allowing you to copy from lots
of sources in one request. This will copy documents from the
<code class="literal">twitter</code> and <code class="literal">blog</code> indices:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": ["twitter", "blog"]
  },
  "dest": {
    "index": "all_together"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1546.console"></div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The Reindex API makes no effort to handle ID collisions so the last
document written will "win" but the order isn’t usually predictable so it is
not a good idea to rely on this behavior. Instead, make sure that IDs are unique
using a script.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-filter-source"></a>Reindex select fields with a source filter<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use source filtering to reindex a subset of the fields in the original documents.
For example, the following request only reindexes the <code class="literal">user</code> and <code class="literal">_doc</code> fields of each document:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "twitter",
    "_source": ["user", "_doc"]
  },
  "dest": {
    "index": "new_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1547.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-change-name"></a>Reindex to change the name of a field<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p><code class="literal">_reindex</code> can be used to build a copy of an index with renamed fields. Say you
create an index containing documents that look like this:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST test/_doc/1?refresh
{
  "text": "words words",
  "flag": "foo"
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1548.console"></div>
<p>but you don’t like the name <code class="literal">flag</code> and want to replace it with <code class="literal">tag</code>.
<code class="literal">_reindex</code> can create the other index for you:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "test"
  },
  "dest": {
    "index": "test2"
  },
  "script": {
    "source": "ctx._source.tag = ctx._source.remove(\"flag\")"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1549.console"></div>
<p>Now you can get the new document:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET test2/_doc/1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1550.console"></div>
<p>which will return:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "found": true,
  "_id": "1",
  "_index": "test2",
  "_type": "_doc",
  "_version": 1,
  "_seq_no": 44,
  "_primary_term": 1,
  "_source": {
    "text": "words words",
    "tag": "foo"
  }
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-daily-indices"></a>Reindex daily indices<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use <code class="literal">_reindex</code> in combination with <a class="xref" href="modules-scripting-painless.html" title="Painless scripting language">Painless</a> to reindex
daily indices to apply a new template to the existing documents.</p>
<p>Assuming you have indices that contain documents like:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT metricbeat-2016.05.30/_doc/1?refresh
{"system.cpu.idle.pct": 0.908}
PUT metricbeat-2016.05.31/_doc/1?refresh
{"system.cpu.idle.pct": 0.105}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1551.console"></div>
<p>The new template for the <code class="literal">metricbeat-*</code> indices is already loaded into Elasticsearch,
but it applies only to the newly created indices. Painless can be used to reindex
the existing documents and apply the new template.</p>
<p>The script below extracts the date from the index name and creates a new index
with <code class="literal">-1</code> appended. All data from <code class="literal">metricbeat-2016.05.31</code> will be reindexed
into <code class="literal">metricbeat-2016.05.31-1</code>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "metricbeat-*"
  },
  "dest": {
    "index": "metricbeat"
  },
  "script": {
    "lang": "painless",
    "source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1552.console"></div>
<p>All documents from the previous metricbeat indices can now be found in the <code class="literal">*-1</code> indices.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET metricbeat-2016.05.30-1/_doc/1
GET metricbeat-2016.05.31-1/_doc/1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1553.console"></div>
<p>The previous method can also be used in conjunction with <a class="xref" href="docs-reindex.html#docs-reindex-change-name" title="Reindex to change the name of a field">changing a field name</a>
to load only the existing data into the new index and rename any fields if needed.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docs-reindex-api-subset"></a>Extract a random subset of an index<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p><code class="literal">_reindex</code> can be used to extract a random subset of an index for testing:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "max_docs": 10,
  "source": {
    "index": "twitter",
    "query": {
      "function_score" : {
        "random_score" : {},
        "min_score" : 0.9    <a id="CO558-1"></a><i class="conum" data-value="1"></i>
      }
    }
  },
  "dest": {
    "index": "random_twitter"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1554.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO558-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>You may need to adjust the <code class="literal">min_score</code> depending on the relative amount of
data extracted from source.</p>
</td>
</tr>
</table>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="reindex-scripts"></a>Modify documents during reindexing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Like <code class="literal">_update_by_query</code>, <code class="literal">_reindex</code> supports a script that modifies the
document. Unlike <code class="literal">_update_by_query</code>, the script is allowed to modify the
document’s metadata. This example bumps the version of the source document:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter",
    "version_type": "external"
  },
  "script": {
    "source": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}",
    "lang": "painless"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1555.console"></div>
<p>Just as in <code class="literal">_update_by_query</code>, you can set <code class="literal">ctx.op</code> to change the
operation that is executed on the destination index:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">noop</code>
</span>
</dt>
<dd>
Set <code class="literal">ctx.op = "noop"</code> if your script decides that the document doesn’t have
to be indexed in the destination index. This no operation will be reported
in the <code class="literal">noop</code> counter in the <a class="xref" href="docs-reindex.html#docs-reindex-api-response-body" title="Response body">response body</a>.
</dd>
<dt>
<span class="term">
<code class="literal">delete</code>
</span>
</dt>
<dd>
Set <code class="literal">ctx.op = "delete"</code> if your script decides that the document must be
 deleted from the destination index. The deletion will be reported in the
 <code class="literal">deleted</code> counter in the <a class="xref" href="docs-reindex.html#docs-reindex-api-response-body" title="Response body">response body</a>.
</dd>
</dl>
</div>
<p>Setting <code class="literal">ctx.op</code> to anything else will return an error, as will setting any
other field in <code class="literal">ctx</code>.</p>
<p>Think of the possibilities! Just be careful; you are able to
change:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<code class="literal">_id</code>
</li>
<li class="listitem">
<code class="literal">_index</code>
</li>
<li class="listitem">
<code class="literal">_version</code>
</li>
<li class="listitem">
<code class="literal">_routing</code>
</li>
</ul>
</div>
<p>Setting <code class="literal">_version</code> to <code class="literal">null</code> or clearing it from the <code class="literal">ctx</code> map is just like not
sending the version in an indexing request; it will cause the document to be
overwritten in the target index regardless of the version on the target or the
version type you use in the <code class="literal">_reindex</code> request.</p>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="reindex-from-remote"></a>Reindex from remote<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Reindex supports reindexing from a remote Elasticsearch cluster:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "remote": {
      "host": "http://otherhost:9200",
      "username": "user",
      "password": "pass"
    },
    "index": "source",
    "query": {
      "match": {
        "test": "data"
      }
    }
  },
  "dest": {
    "index": "dest"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1556.console"></div>
<p>The <code class="literal">host</code> parameter must contain a scheme, host, port (e.g.
<code class="literal">https://otherhost:9200</code>), and optional path (e.g. <code class="literal">https://otherhost:9200/proxy</code>).
The <code class="literal">username</code> and <code class="literal">password</code> parameters are optional, and when they are present <code class="literal">_reindex</code>
will connect to the remote Elasticsearch node using basic auth. Be sure to use <code class="literal">https</code> when
using basic auth or the password will be sent in plain text.
There are a range of <a class="xref" href="docs-reindex.html#reindex-ssl" title="Configuring SSL parameters">settings</a> available to configure the behaviour of the
 <code class="literal">https</code> connection.</p>
<p>Remote hosts have to be explicitly allowed in elasticsearch.yml using the
<code class="literal">reindex.remote.whitelist</code> property. It can be set to a comma delimited list
of allowed remote <code class="literal">host</code> and <code class="literal">port</code> combinations. Scheme is
ignored, only the host and port are used. For example:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">reindex.remote.whitelist: "otherhost:9200, another:9200, 127.0.10.*:9200, localhost:*"</pre>
</div>
<p>The list of allowed hosts must be configured on any nodes that will coordinate the reindex.</p>
<p>This feature should work with remote clusters of any version of Elasticsearch
you are likely to find. This should allow you to upgrade from any version of
Elasticsearch to the current version by reindexing from a cluster of the old
version.</p>
<div class="warning admon">
<div class="icon"></div>
<div class="admon_content">
<p>Elasticsearch does not support forward compatibility across major versions. For
example, you cannot reindex from a 7.x cluster into a 6.x cluster.</p>
</div>
</div>
<p>To enable queries sent to older versions of Elasticsearch the <code class="literal">query</code> parameter
is sent directly to the remote host without validation or modification.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Reindexing from remote clusters does not support
<a class="xref" href="docs-reindex.html#docs-reindex-manual-slice" title="Manual slicing">manual</a> or
<a class="xref" href="docs-reindex.html#docs-reindex-automatic-slice" title="Automatic slicing">automatic slicing</a>.</p>
</div>
</div>
<p>Reindexing from a remote server uses an on-heap buffer that defaults to a
maximum size of 100mb. If the remote index includes very large documents you’ll
need to use a smaller batch size. The example below sets the batch size to <code class="literal">10</code>
which is very, very small.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "remote": {
      "host": "http://otherhost:9200"
    },
    "index": "source",
    "size": 10,
    "query": {
      "match": {
        "test": "data"
      }
    }
  },
  "dest": {
    "index": "dest"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1557.console"></div>
<p>It is also possible to set the socket read timeout on the remote connection
with the <code class="literal">socket_timeout</code> field and the connection timeout with the
<code class="literal">connect_timeout</code> field. Both default to 30 seconds. This example
sets the socket read timeout to one minute and the connection timeout to 10
seconds:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _reindex
{
  "source": {
    "remote": {
      "host": "http://otherhost:9200",
      "socket_timeout": "1m",
      "connect_timeout": "10s"
    },
    "index": "source",
    "query": {
      "match": {
        "test": "data"
      }
    }
  },
  "dest": {
    "index": "dest"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1558.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="reindex-ssl"></a>Configuring SSL parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/reindex.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Reindex from remote supports configurable SSL settings. These must be
specified in the <code class="literal">elasticsearch.yml</code> file, with the exception of the
secure settings, which you add in the Elasticsearch keystore.
It is not possible to configure SSL in the body of the <code class="literal">_reindex</code> request.</p>
<p>The following settings are supported:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">reindex.ssl.certificate_authorities</code>
</span>
</dt>
<dd>
List of paths to PEM encoded certificate files that should be trusted.
You cannot specify both <code class="literal">reindex.ssl.certificate_authorities</code> and
<code class="literal">reindex.ssl.truststore.path</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.truststore.path</code>
</span>
</dt>
<dd>
The path to the Java Keystore file that contains the certificates to trust.
This keystore can be in "JKS" or "PKCS#12" format.
You cannot specify both <code class="literal">reindex.ssl.certificate_authorities</code> and
<code class="literal">reindex.ssl.truststore.path</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.truststore.password</code>
</span>
</dt>
<dd>
The password to the truststore (<code class="literal">reindex.ssl.truststore.path</code>).
This setting cannot be used with <code class="literal">reindex.ssl.truststore.secure_password</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.truststore.secure_password</code> (<a class="xref" href="secure-settings.html" title="Secure settings">Secure</a>)
</span>
</dt>
<dd>
The password to the truststore (<code class="literal">reindex.ssl.truststore.path</code>).
This setting cannot be used with <code class="literal">reindex.ssl.truststore.password</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.truststore.type</code>
</span>
</dt>
<dd>
The type of the truststore (<code class="literal">reindex.ssl.truststore.path</code>).
Must be either <code class="literal">jks</code> or <code class="literal">PKCS12</code>. If the truststore path ends in ".p12", ".pfx"
or "pkcs12", this setting defaults to <code class="literal">PKCS12</code>. Otherwise, it defaults to <code class="literal">jks</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.verification_mode</code>
</span>
</dt>
<dd>
Indicates the type of verification to protect against man in the middle attacks
and certificate forgery.
One of <code class="literal">full</code> (verify the hostname and the certificate path), <code class="literal">certificate</code>
(verify the certificate path, but not the hostname) or <code class="literal">none</code> (perform no
verification - this is strongly discouraged in production environments).
Defaults to <code class="literal">full</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.certificate</code>
</span>
</dt>
<dd>
Specifies the path to the PEM encoded certificate (or certificate chain) to be
used for HTTP client authentication (if required by the remote cluster)
This setting requires that <code class="literal">reindex.ssl.key</code> also be set.
You cannot specify both <code class="literal">reindex.ssl.certificate</code> and <code class="literal">reindex.ssl.keystore.path</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.key</code>
</span>
</dt>
<dd>
Specifies the path to the PEM encoded private key associated with the
certificate used for client authentication (<code class="literal">reindex.ssl.certificate</code>).
You cannot specify both <code class="literal">reindex.ssl.key</code> and <code class="literal">reindex.ssl.keystore.path</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.key_passphrase</code>
</span>
</dt>
<dd>
Specifies the passphrase to decrypt the PEM encoded private key
(<code class="literal">reindex.ssl.key</code>) if it is encrypted.
Cannot be used with <code class="literal">reindex.ssl.secure_key_passphrase</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.secure_key_passphrase</code> (<a class="xref" href="secure-settings.html" title="Secure settings">Secure</a>)
</span>
</dt>
<dd>
Specifies the passphrase to decrypt the PEM encoded private key
(<code class="literal">reindex.ssl.key</code>) if it is encrypted.
Cannot be used with <code class="literal">reindex.ssl.key_passphrase</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.keystore.path</code>
</span>
</dt>
<dd>
Specifies the path to the keystore that contains a private key and certificate
to be used for HTTP client authentication (if required by the remote cluster).
This keystore can be in "JKS" or "PKCS#12" format.
You cannot specify both <code class="literal">reindex.ssl.key</code> and <code class="literal">reindex.ssl.keystore.path</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.keystore.type</code>
</span>
</dt>
<dd>
The type of the keystore (<code class="literal">reindex.ssl.keystore.path</code>). Must be either <code class="literal">jks</code> or <code class="literal">PKCS12</code>.
If the keystore path ends in ".p12", ".pfx" or "pkcs12", this setting defaults
to <code class="literal">PKCS12</code>. Otherwise, it defaults to <code class="literal">jks</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.keystore.password</code>
</span>
</dt>
<dd>
The password to the keystore (<code class="literal">reindex.ssl.keystore.path</code>). This setting cannot be used
with <code class="literal">reindex.ssl.keystore.secure_password</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.keystore.secure_password</code> (<a class="xref" href="secure-settings.html" title="Secure settings">Secure</a>)
</span>
</dt>
<dd>
The password to the keystore (<code class="literal">reindex.ssl.keystore.path</code>).
This setting cannot be used with <code class="literal">reindex.ssl.keystore.password</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.keystore.key_password</code>
</span>
</dt>
<dd>
The password for the key in the keystore (<code class="literal">reindex.ssl.keystore.path</code>).
Defaults to the keystore password. This setting cannot be used with
<code class="literal">reindex.ssl.keystore.secure_key_password</code>.
</dd>
<dt>
<span class="term">
<code class="literal">reindex.ssl.keystore.secure_key_password</code> (<a class="xref" href="secure-settings.html" title="Secure settings">Secure</a>)
</span>
</dt>
<dd>
The password for the key in the keystore (<code class="literal">reindex.ssl.keystore.path</code>).
Defaults to the keystore password. This setting cannot be used with
<code class="literal">reindex.ssl.keystore.key_password</code>.
</dd>
</dl>
</div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="docs-bulk.html">« Bulk API</a>
</span>
<span class="next">
<a href="docs-termvectors.html">Term vectors API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
